package com.xujl.task;

import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.List;

/**
 * <pre>
 *     @author : xujl
 *     e-mail : 597355068@qq.com
 *     time   : 2018/7/20
 *     desc   :
 *     version: 1.0
 * </pre>
 */
public class RxLifeList {
    private List<WeakReference<RxLife>> mRxLifeList;

    public RxLifeList () {
        mRxLifeList = new ArrayList<>();
    }

    public void add (RxLife life) {
        if (life == null) {
            return;
        }
        mRxLifeList.add(new WeakReference<>(life));
    }

    public void doUnbind () {
        RxExecutor.getInstance().printRunnableMsg();
        for (WeakReference<RxLife> rxLife : mRxLifeList) {
            if (rxLife != null && rxLife.get() != null) {
                rxLife.get().doUnbind();
            }
        }
        mRxLifeList.clear();
        RxExecutor.getInstance().printRunnableMsg();
    }

}
